﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Daco.Web.UI;
using Daco.Security;

namespace Daco.Web.Pages.Secure
{
    public partial class EditFooter : SitePage
    {
        public EditFooter()
            : base("Secure", "EditFooter", new Security.CPermission(EPermission.SelectAccess | EPermission.UpdateAccess))
        {
            this.Init += new EventHandler(EditFooter_Init);
            this.Load += new EventHandler(EditFooter_Load);
        }

        void EditFooter_Init(object sender, EventArgs e)
        {
            tbxContent.BasePath = Page.ResolveUrl("~/FCKEditor/");
        }

        void EditFooter_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                tbxContent.Value = CWeb.GetFooter();
            }
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            string content = tbxContent.Value.Trim();

            if (!string.IsNullOrEmpty(content))
            {
                if (CWeb.UpdateFooter(content))
                {
                    CMessageBox.Show(Page, Daco.Web.Resources.Messages.UpdateSuccess);
                }
                else
                    CMessageBox.Show(Page, Daco.Web.Resources.Messages.UpdateFailed);
            }
            else
                CMessageBox.Show(Page, string.Format(Daco.Web.Resources.Messages.RequiredField, "Footer"));
        }
    }
}